package string;

import java.util.Random;
import java.util.Scanner;

public class work {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        Random random=new Random();
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        int num=4;
        String code="";
        int index;
        while(true) {
            for (int i = 0; i < num; i++) {
                index = random.nextInt(str.length());
               //(int) (Math.random() * str.length());
                code += str.charAt(index);

            }
            System.out.println("请输入验证码：" + code);
            String reply = scan.next();
            if (reply.toUpperCase().equals(code.toUpperCase())) {
                System.out.println("输入正确");
                break;
            } else {
                System.out.println("输入错误，请重新验证");
                code="";
            }
        }


    }
}
